package com.ayoka.parenting.ui.grown.share;

import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.ViewGroup;

import com.ayoka.parenting.R;
import com.ayoka.parenting.bean.ClassroomDetailBean;
import com.ayoka.parenting.interf.SimpleRequestCallback;
import com.ayoka.parenting.mvp.BasePresenterImpl;
import com.jincp.common.dialog.DialogDismissListener;
import com.jincp.common.dialog.DialogResultListener;
import com.jincp.common.utils.UIUtils;

/**
 * @ProjectName: MVPPlugin.
 * @ClassName: GrownCourseSharePresenter.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/10/10 18:17.
 */
public class GrownCourseSharePresenter extends BasePresenterImpl<GrownCourseShareContract.View> implements GrownCourseShareContract.Presenter {

    private GrownCourseShareModel model;

    public GrownCourseSharePresenter() {
        model = new GrownCourseShareModel();
    }

    @Override
    public void getGrownClassroomShareData(String classroomId) {
        mView.get().showWaitDialog(UIUtils.getString(R.string.loading));
        model.getGrownClassroomShareData(this, classroomId, new SimpleRequestCallback<ClassroomDetailBean>() {
            @Override
            public void onSuccess(ClassroomDetailBean data) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().configClassroomDetailData(data);
            }

            @Override
            public void onFailure(int errCode, String errMsg) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().showToast(errMsg);
            }
        });
    }

    @Override
    public void showPictureOperatorDialog(FragmentManager fragmentManager) {
        PictureOperatorDialog dialog = new PictureOperatorDialog.Builder()
                .setGravity(Gravity.BOTTOM)
                .setSize(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                .build();
        dialog.setDialogResultListener(new DialogResultListener() {
            @Override
            public void result(DialogFragment dialogFragment, Object result) {
                dialogFragment.dismissAllowingStateLoss();
                if (!isAttached()) return;
                String operator = (String) result;
                if (TextUtils.equals("SAVE", operator)) {
                    mView.get().onSavePictureClick();
                } else if (TextUtils.equals("SHARE", operator)) {
                    mView.get().onSharePictureClick();
                }
            }
        });
        dialog.show(fragmentManager, "PictureOperatorDialog");
    }
}
